package view;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Dictionary;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSlider;
import javax.swing.JTextArea;
import javax.swing.JTextField;

import model.Paper;
import model.Recommendation;
import model.User;

/**
 * This class is for the recommendation form.
 * 
 * @author Cody Thompson
 * @author Rylie Nelson
 *
 */
public class RecForm extends JFrame {

	private JButton btnConfirm;
	
	private Paper papel;
	
	private JTextArea texty;
	
	private User me;
	
	private JSlider miniBurger;
	
	public RecForm(Paper p, User use, Recommendation r) {
		super("Recommendation");
		papel = p;
		me = use;
		texty = new JTextArea();
		miniBurger = new JSlider();
		texty.setText(r.getReason());
		texty.setLineWrap(true);
		miniBurger.setValue(r.getRating());
		init();
		pack();
	}
	
	public RecForm(Paper p, User use) {
		super();
		papel = p;
		me = use;
		texty = new JTextArea();
		miniBurger = new JSlider();
		init();
		pack();
	}
	
	private void init() {
		setPreferredSize(new Dimension(400,400));
		setLayout(new BorderLayout());
		JPanel flan = new JPanel();
		flan.setLayout(new BorderLayout());
		btnConfirm = new JButton("Confirm");
		JScrollPane scrollPane = new JScrollPane();
		add(scrollPane, BorderLayout.CENTER);
		scrollPane.setViewportView(texty);
		add(btnConfirm, BorderLayout.SOUTH);
		miniBurger.setMajorTickSpacing(1);
		miniBurger.setMinorTickSpacing(0);
		miniBurger.setMaximum(5);
		miniBurger.setMinimum(1);
		miniBurger.setSnapToTicks(true);
		miniBurger.setPaintTicks(true);
		miniBurger.setPaintLabels(true);
		flan.add(miniBurger, BorderLayout.CENTER);
		flan.add(new JLabel("        Please rate the paper 1-5"), BorderLayout.NORTH);
		flan.add(new JLabel("        Give a rationale for your recommendation"), BorderLayout.SOUTH);
		add(flan, BorderLayout.NORTH);
		btnConfirm.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				if (texty.getText() == "") {
					//do a big fat nothing
				} else {
					papel.addRecommendation(new Recommendation(miniBurger.getValue(), texty.getText(), me));
					dispose();
				}
			}			
		});
	}
}
